package com.test.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HiService {
    @Autowired
    RestTemplate restTemplate;

    /*@HystrixCommand(fallbackMethod = "hiFallback",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2500")
    })*/
    @HystrixCommand(fallbackMethod = "hiFallback")
    public String hi(String name) {
        return restTemplate.getForObject("http://provider/hi?name="+name,String.class);
    }

    public String hiFallback(String name){
        return "服务出错了，请稍后";
    }
}
